<%@page import="com.wowangz.cms.common.utils.SysConstant.NewsBusinessstatus"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/pageHead.jsp"%>
<script type="text/javascript">
	function view(val){
		var id = val;
		$(this).isswindow({
			noheader : true,
			url :"${systemctx}/topic/news/toNewsViewPage.web?id="+id
		});
	}
	function addInfo(){
		$(this).isswindow({
			noheader : true,
			url :"${systemctx}/topic/poster/toPosterAdd.web"
		});
	}
	
	function publistPoster(status){
		var ids = getIds(status);
		if(ids != undefined){
			var msg = '<%=MessageResourcesUtils.getMessage(request, "topic.poster.status.alert6")%>';
			if(status != <%=SysConstant.CommonUsedStatus.STOP%>){
				msg = '<%=MessageResourcesUtils.getMessage(request, "topic.poster.status.alert5")%>';
			}
			if(confirm(msg)){
				// 显示进度条
				showSending();
				$.get('${systemctx}/topic/poster/startOrStopPoster.json?ids=' + ids +'&status=' + status,function(data){
					//关闭执行...
					closeSending();
					data = jQuery.parseJSON(data);
					if(data.messagetype == 1){
						alert(data.message);
						$('#datagrid').datagrid('clearSelections');
						$('#datagrid').datagrid('load',$('#form1').serializeObject());
					}else {
						alert(data.message);
						return ;
					}
				});
			}
		}
		
	}
	
	function deletePoster(id){
		var msg = '<%=MessageResourcesUtils.getMessage(request, "alertinfo.common.jsp.alert2")%>';
		if(confirm(msg)){
			// 显示进度条
			showSending();
			$.get('${systemctx}/topic/poster/deletePoster.json?id=' + id ,function(data){
				//关闭执行...
				closeSending();
				data = jQuery.parseJSON(data);
				if(data.messagetype == 1){
					alert(data.message);
					$('#datagrid').datagrid('load',$('#form1').serializeObject());
				}else {
					alert(data.message);
					return ;
				}
			});
		}
	}
	
	function getIds(status){
		var rows = $('#datagrid').datagrid('getSelections');
		var ids = "";
		if(rows.length <= 0){
			alert('<%=MessageResourcesUtils.getMessage(request, "systemmanage.headautotask.list.alert")%>');
			return ;
		} else {
			if(status == <%=SysConstant.CommonUsedStatus.STOP%>){
				for(var i = 0; i < rows.length ; i++){
					var row = rows[i];
					if(row.status == <%=SysConstant.CommonUsedStatus.START%>){
						ids += row.id + ",";
					} else {
						var msg = '<%=MessageResourcesUtils.getMessage(request, "topic.poster.select.alert4")%>'
						alert(msg);
						return ;
					}
				}
			} else {
				for(var i = 0; i < rows.length ; i++){
					var row = rows[i];
					if(row.status == <%=SysConstant.CommonUsedStatus.STOP%>){
						ids += row.id + ",";
					} else {
						var msg = '<%=MessageResourcesUtils.getMessage(request, "topic.poster.select.alert3")%>'
						alert(msg);
						return ;
					}
				}
			}
			if(ids != ''){
				ids = ids.substring(0, ids.length - 1);
			} else {
				if(status == <%=SysConstant.CommonUsedStatus.STOP%>){
					alert('<%=MessageResourcesUtils.getMessage(request, "topic.poster.select.alert2")%>');
					return ;
				}else {
					alert('<%=MessageResourcesUtils.getMessage(request, "topic.poster.select.alert1")%>');
					return ;
				}
			}
		}
		return ids;
	}
	
	function query_datagrid(){
		//加载分页控件 datagrid
		$('#datagrid').issdatagrid({
			formid : 'form1',
			title : '<%=MessageResourcesUtils.getMessage(request, "topic.news.list.title")%>',
			singleSelect : false,
			striped : true,
			url : '${systemctx}/topic/poster/getPosterJson.json',
			sortName: 'sortnumber',
			sortOrder: 'asc',
			remoteSort : true,
			idField : 'id',
			rownumbers : true,
			queryParams:$('#form1').serializeObject(),
			frozenColumns :[[
 				{field:'ck', checkbox:true},
 				{field : 'id',title : '<%=MessageResourcesUtils.getMessage(request, "common.button.operation")%>',align : 'center',formatter : function(value,row,index) {
 						var str = '';	
 						/* str += "<a href=\"javascript:void(0);\" onclick=\"getView(\'"+row.id+"\')\">预览</a>"; */
		      			str += '<a href="javascript:void(0);" class="easyui-linkbutton" onclick="editPoster(' + row.id + ')"><%=MessageResourcesUtils.getMessage(request,"common.button.update") %></a> ';
		      			if(row.status == '<%=SysConstant.CommonUsedStatus.START%>'){
		      				str += '<a href="javascript:void(0);" class="easyui-linkbutton" style="cursor: default;" disabled="disabled"><%=MessageResourcesUtils.getMessage(request,"common.button.delete") %></a> ';
		      			}else {
			      			str += '<a href="javascript:void(0);" class="easyui-linkbutton" onclick="deletePoster(' + row.id + ')"><%=MessageResourcesUtils.getMessage(request,"common.button.delete") %></a> ';
		      			}
		    			return str;
	    			}
	        	},
 				{title : '<%=MessageResourcesUtils.getMessage(request,"topic.poster.col.filename")%>',field : 'filename',sortable : true,width:310,align : 'left',formatter: function(value,row,index){
 					 	  return "<a id=\""+row.id+"\" href=\"javascript:void(0);\" onclick=\"getView(\'"+row.id+"\')\">"+value+"</a>";
 					  }
 				},  
 				{title : '<%=MessageResourcesUtils.getMessage(request,"topic.poster.col.filesize")%>',field : 'filesize',sortable : true,align : 'left',width:100}, 
 				{title : '<%=MessageResourcesUtils.getMessage(request,"topic.poster.col.mongofilename")%>',field : 'mongofilename',sortable : true,align : 'left',width:300}, 
 			]],
 			columns : [[  
              	{title : '<%=MessageResourcesUtils.getMessage(request,"topic.poster.col.sortnumber")%>',field : 'sortnumber',sortable : true,align : 'left',width:70}, 
              	{title : '<%=MessageResourcesUtils.getMessage(request,"topic.poster.col.suffix")%>',field : 'suffix',sortable : true,align : 'left',width:80}, 
              	<%-- {title : '<%=MessageResourcesUtils.getMessage(request,"topic.poster.col.type")%>',field : 'type',sortable : true,align : 'left',width:100}, --%> 
              	{title : '<%=MessageResourcesUtils.getMessage(request,"topic.poster.col.statusname")%>',field : 'statusname',sortable : true,align : 'center',width:80} 
            ]],
			onLoadSuccess : function(data) {
				$("#datagrid").datagrid("clearSelections");

			}
		});
	}
	$(document).ready(function() {
		query_datagrid();
		$('#butQuery').click(function() {
			$('#datagrid').datagrid('load',$('#form1').serializeObject());
		});
		$(".show-div").css({
			'left':document.body.offsetWidth / 3
		});
		$("#dialog").dialog('close');
	});
	
	
	function editPoster(id){
		$(this).isswindow({
			noheader : true,
			url :'${systemctx}/topic/poster/toPosterEdit.web?id='+id
		});
	}
	
	function getView(id){
		$("#dialog").dialog('open');
		$("#dialog").dialog({
			title:'<%=MessageResourcesUtils.getMessage(request, "topic.poster.view.title")%>',
			modal:true,
			width:512,
			height:500
		});
		$.get('${systemctx}/topic/poster/findOnePoster.json?id=' + id ,function(data){
			data = jQuery.parseJSON(data)
			var poster = data.object;
			var content = "";
			if(data.resposecode == 200){
				var url = poster.pictureUrl + "/" +poster.mongofilename;
				$("#img").attr("src",url);
			} else {
				content = data.message;
			}
		}); 
		//$(".show-div").slideUp();
		/* $.get('${systemctx}/topic/poster/findOne.json?id=' + id ,function(data){
			data = jQuery.parseJSON(data)
			var poster = data.object;
			var content = "";
			if(data.resposecode == 200){
				var url = poster.pictureUrl + "/" +poster.mongofilename;
				content = "<img class='show-img' id='img' src='"+url+"' />";
			} else {
				content = data.message;
			}
			var mask_msg = "<div id='show-img'>" + content + "</div>"
			
			$(".content").html(mask_msg);
			$(".show-div").slideDown(1000,'linear');
		}); */
	}

	function imageClose(){
		$(".show-div").slideUp();
	}
</script>
<style type="text/css">
	.show-div {
		position: absolute;
		z-index: 9007;
		display:none;
		width: 400px;
		background:graytext;
		overflow:hidden;
		min-width:10px;
	}
	.show-img {
		width: 500px;
		display:block;
		position: relative;
	}
</style>
<%-- <div class="show-div">
	<div style="z-index:9010;position:absolute;right:0px" id="toolbar">
		<a href='javascript:void(0)' onclick='imageClose()' style="float:right;" id='close-div'>
			<img alt="" src="${systemctx}/resources/images/imgbox-close.png">
		</a>
	</div>
	<div class="content">
		
	</div>
</div> --%>
<div id="dialog" class="easyui-dialog">
	<div id='show-img'><img class='show-img' id='img' /></div>
</div>
<form action="" id="form1" name="form1">
	<div class="pageMain">
		<div class="pageTitle">
			<%=MessageResourcesUtils.getMessage(request, "systemmanage.contentmanagement.title")%>
			<span></span>
			<%=MessageResourcesUtils.getMessage(request, "topic.poster.title")%>
			<span></span>
			<%=MessageResourcesUtils.getMessage(request, "topic.poster.list.title")%>
		</div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li>
						<i></i> 
						<label>
							<!-- 上级栏目 -->
							<%=MessageResourcesUtils.getMessage(request, "topic.poster.col.filename") %>
						</label>
						<span>
							<input type="text" name="filename" id="filename">
						</span>		
					</li>
				</ul>
			</div>
		</div>
		<div class="button-group">
			<input type="button" class="btn btn-default" id="butQuery" value="<%=MessageResourcesUtils.getMessage(request,"common.button.query") %>" />
			<input type="button" class="btn btn-default" onclick="addInfo()" value="<%=MessageResourcesUtils.getMessage(request,"common.button.add") %>" />
			<input type="button" class="btn btn-default" onclick="publistPoster(1)" value="<%=MessageResourcesUtils.getMessage(request,"topic.poster.col.statusstart") %>" />
			<input type="button" class="btn btn-default" onclick="publistPoster(2)" value="<%=MessageResourcesUtils.getMessage(request,"topic.poster.col.statusstop") %>" />
		</div>
		<table style="width: 100%">
			<tr>
				<td>
					<table id="datagrid"></table>
				</td>
			</tr>
		</table>				
	</div>
</form>

<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>